package com.example.wszb.ui.activity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.wszb.R;
import com.example.wszb.ui.fragment.AddFragment;
import com.example.wszb.ui.fragment.HistoryFragment;
import com.example.wszb.ui.fragment.InfoFragment;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private LinearLayout mMenuHistory;
    private LinearLayout mMenuAdd;
    private LinearLayout mMenuInfo;

    private HistoryFragment historyFragment = new HistoryFragment();
    private AddFragment addFragment = new AddFragment();
    private InfoFragment infoFragment = new InfoFragment();

    ImageView historyImg;
    ImageView addImg;
    ImageView infoImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null)
            actionBar.hide();

        initView();

        historyImg = (ImageView) findViewById(R.id.caidan_history);
        addImg = (ImageView) findViewById(R.id.caidan_add);
        infoImg = (ImageView) findViewById(R.id.caidan_info);


        this.getFragmentManager().beginTransaction()
                .replace(R.id.container_content,historyFragment).commit();

    }

    private void initView() {
        mMenuHistory = this.findViewById(R.id.menu_history);
        mMenuAdd = this.findViewById(R.id.menu_add);
        mMenuInfo = this.findViewById(R.id.menu_info);

        mMenuHistory.setOnClickListener(this);
        mMenuAdd.setOnClickListener(this);
        mMenuInfo.setOnClickListener(this);
    }

    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.menu_history:
                historyImg.setImageResource(R.mipmap.history);
                addImg.setImageResource(R.mipmap.add);
                infoImg.setImageResource(R.mipmap.info);
                this.getFragmentManager().beginTransaction()
                        .replace(R.id.container_content,historyFragment)
                        .commit();break;
            case R.id.menu_add:
                historyImg.setImageResource(R.mipmap.history);
                addImg.setImageResource(R.mipmap.add);
                infoImg.setImageResource(R.mipmap.info);
                startActivity(new Intent(MainActivity.this,CameraActivity.class));

            case R.id.menu_info:
                historyImg.setImageResource(R.mipmap.history);
                addImg.setImageResource(R.mipmap.add);
                infoImg.setImageResource(R.mipmap.info);
                this.getFragmentManager().beginTransaction()
                        .replace(R.id.container_content,infoFragment)
                        .commit();break;
            default:break;
        }
    }
}